﻿<wnd:WindowBase  x:Class="ThemeManagementModule.ThemeMngView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wnd="clr-namespace:Eniux.Windows.Controls.WindowCore;assembly=Eniux.Windows.Controls"
        WindowStartupLocation="CenterScreen" x:Name="root" ResizeMode="NoResize"
        xmlns:core="clr-namespace:Eniux.Windows.Controls.Core.Core;assembly=Eniux.Windows.Controls.Core"
        xmlns:converter="clr-namespace:Eniux.Windows.Controls.Core.Converters;assembly=Eniux.Windows.Controls.Core"
        Width="400" Height="350" 
        Title="主题管理" >
    <Window.Resources>
        <converter:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <converter:OpacityScaleConverter x:Key="OpacityScaleConverter"/>
        <DrawingBrush Viewport="0.0,0.0,10,10" ViewportUnits="Absolute" TileMode="Tile"   x:Key="alphaBackground"    >

            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing Brush="White">
                        <GeometryDrawing.Geometry>
                            <RectangleGeometry Rect="0,0,5,5" />
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>

                    <GeometryDrawing>
                        <GeometryDrawing.Geometry>
                            <GeometryGroup>
                                <RectangleGeometry Rect="0,0,5,5" />
                                <RectangleGeometry Rect="5,5,5,5" />
                            </GeometryGroup>
                        </GeometryDrawing.Geometry>
                        <GeometryDrawing.Brush>
                            <SolidColorBrush Color="#d7d7d7"/>

                        </GeometryDrawing.Brush>
                    </GeometryDrawing>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </Window.Resources>
    <Grid>
        <StackPanel>
        <TabControl BorderThickness="0,1,0,0" Margin="-7,0,-7,0" Background="Transparent">
            <TabItem Header="更换背景图片" x:Name="ChangeBackImage">
                    <ScrollViewer MaxHeight="211" Height="211"  CanContentScroll="True" HorizontalAlignment="Center" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
                        <ListBox x:Name="BackImageRoot" PreviewMouseDown="BackImageRoot_PreviewMouseDown" SelectionChanged="BackImageRoot_SelectionChanged" SelectedIndex="{Binding SelectedImageIndex}" BorderBrush="Transparent" Background="Transparent" Style="{x:Null}" ItemsSource="{Binding BackImageCollection,IsAsync=True}">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="ListBoxItem" BasedOn="{x:Null}">
                                    <Setter Property="Width" Value="105"/>
                                    <Setter Property="Height" Value="75"/>
                                    <Setter Property="Margin" Value="0,4,4,4"/>
                                    <Setter Property="Padding" Value="0"/>
                                    <Setter Property="BorderBrush" Value="Silver"/>
                                    <Style.Triggers>
                                        <Trigger Property="IsMouseOver" Value="true">
                                            <Setter Property="BorderBrush" Value="Orange"/>
                                        </Trigger>
                                        <Trigger Property="IsSelected" Value="true">
                                            <Setter Property="BorderBrush" Value="OrangeRed"/>
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </ListBox.ItemContainerStyle>
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate >
                                    <WrapPanel Width="335"  Orientation="Horizontal" IsItemsHost="True" Margin="5" VirtualizingStackPanel.IsVirtualizing="True"/>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid Background="White" >
                                        <Rectangle SnapsToDevicePixels="true" StrokeDashArray="{Binding DC}" StrokeThickness="3" Stroke="{Binding BorderBrush,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ListBoxItem}}">
                                        </Rectangle>
                                        <Image Stretch="UniformToFill" Source="{Binding Value}" Margin="3" SnapsToDevicePixels="True"/>
                                    </Grid>                                    
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </ScrollViewer>
            </TabItem>
            <TabItem Header="系统默认颜色">
                <Border BorderBrush="Black" BorderThickness="0,0,1,1"  HorizontalAlignment="Center">
                        <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                        <WrapPanel Orientation="Vertical"  x:Name="left_root" Margin="0,0,0,0" Grid.Row="0" Width="45" Height="180" Grid.Column="0" ItemHeight="15" ItemWidth="15"/>
                        <WrapPanel Grid.Column="2" Grid.Row="1" Margin="0,0,0,0" Width="270" Height="180" x:Name="right_root" ItemHeight="15" ItemWidth="15"/>
                    </Grid>
                </Border>
            </TabItem>
        </TabControl>
            <Grid Visibility="{Binding IsSelected,ElementName=ChangeBackImage,Converter={StaticResource BooleanToVisibilityConverter}}"  >
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="60"/>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="30"/>
                </Grid.ColumnDefinitions>
                <TextBlock Text="背景颜色" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                <Border Grid.Row="0" Grid.Column="1" Height="22" BorderBrush="LightGray" BorderThickness="1" SnapsToDevicePixels="True">
                    <Grid>
                        <Border Background="{DynamicResource alphaBackground}"></Border>
                        <Border x:Name="sd"  Background="{Binding MainBackground}"></Border>
                    </Grid>
                </Border>

            </Grid>
            <Grid >
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="60"/>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="32"/>
                </Grid.ColumnDefinitions>
                <TextBlock Text="透明度" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                <Slider x:Name="ChangeOpacity"  Grid.Row="2" Maximum="255" Minimum="0" Value="{Binding BackOpacity}" IsSnapToTickEnabled="True"
            TickFrequency="1" Grid.Column="1" VerticalAlignment="Center" ValueChanged="ChangeOpacity_ValueChanged"/>
                <TextBlock Grid.Column="2" Text="{Binding Value,ElementName=ChangeOpacity,Mode=TwoWay,StringFormat={}{0:f0}%,Converter={StaticResource OpacityScaleConverter}}" FontFamily="Segoe UI"   VerticalAlignment="Center" HorizontalAlignment="Left"/>
            </Grid>

            </StackPanel>
    </Grid>
</wnd:WindowBase>
